package com.mf.ergate.web.security;

import org.springframework.security.core.context.SecurityContextHolder;

/**
 * 登陆信息上下文
 * User: zhaoming
 * Date: 15-11-4
 * Time: 下午7:48
 * To change this template use File | Settings | File Templates.
 */
public class LoginContext {

    /**
     * 获取当前用户信息
     */
    public static MfUserDetails getCurrentUser() {
        return (MfUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    /**
     * 获取登录用户信息
     */
    public static LoginUser getLoginUser(){
        MfUserDetails user = (MfUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        LoginUser loginUser = new LoginUser();
        loginUser.setUserNo(user.getUserNo());
        loginUser.setUserName(user.getUserName());
        loginUser.setUserAvatar(user.getUserAvatar());
        return loginUser;
    }

}
